/*
 * @Description: vite.config.ts vite2.0配置
 * @Version: 2.0
 * @Autor: lhl
 * @Date: 2021-04-03 23:18:54
 * @LastEditors: wenbin
 * @LastEditTime: 2021-11-15 16:09:01
 */
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import viteCompression from 'vite-plugin-compression';
import path from 'path';
const resolve = (dir: string) => path.join(__dirname, dir);
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    // 生产环境生成 .gz 文件
    viteCompression({
      verbose: true,
      disable: false,
      threshold: 10240,
      algorithm: 'gzip',
      ext: '.gz',
    }),
  ],
  css: {
    postcss: {
      plugins: [
        // 前缀追加
        require('autoprefixer')({
          overrideBrowserslist: [
            'Android 4.1',
            'iOS 7.1',
            'Chrome > 31',
            'ff > 31',
            'ie >= 8',
            '> 1%',
          ],
          grid: true,
        }),
        require('postcss-flexbugs-fixes'),
      ],
    },
    preprocessorOptions: {
      scss: {
        additionalData: `@import "./src/assets/sass/index.scss";`,
      },
    },
  },
  base: './', // 打包路径
  resolve: {
    // 设置别名
    alias: {
      '@': resolve('src'),
      // 解决vue-i18n警告You are running the esm-bundler build of vue-i18n. It is recommended to configure your bundler to explicitly replace feature flag globals with boolean literals to get proper tree-shaking in the final bundle.
      'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
    },
  },
  server: {
    host: '0.0.0.0',
    https: false,
    port: 4000, // 启动端口
    open: true,
    proxy: {
      '^/api/platform/.*': {
        target: 'http://192.168.20.30:12000', //网关
        changeOrigin: true, //跨域
        rewrite: (path) => path.replace(/^\/api\/platform/, ''),
      },
      '^/api/dataCenter/.*': {
        target: 'http://192.168.20.30:18000', //网关
        // target: 'http://192.168.60.226:18000', //网关
        changeOrigin: true, //跨域
        rewrite: (path) => path.replace(/^\/api\/dataCenter/, ''),
      },
    },
    cors: true,
  },
  build: {
    // 生产环境移除 console
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      },
    },
  },
});
